package com.qinglei.recoup.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qinglei.recoup.common.domain.CommonRes;
import com.qinglei.recoup.common.exception.RecoupException;
import com.qinglei.recoup.common.exception.RedisConnectException;
import com.qinglei.recoup.common.utils.DateTimeUtils;
import com.qinglei.recoup.system.dao.MonitorTimeMapper;
import com.qinglei.recoup.system.domain.Bed;
import com.qinglei.recoup.system.domain.BedMonitorTime;
import com.qinglei.recoup.system.domain.Building;
import com.qinglei.recoup.system.domain.Floor;
import com.qinglei.recoup.system.domain.MonitorTime;
import com.qinglei.recoup.system.domain.Room;
import com.qinglei.recoup.system.pojo.AddMonitorTimeParam;
import com.qinglei.recoup.system.pojo.MonitorInfoTreeVO;
import com.qinglei.recoup.system.pojo.BedMonitorTimeParam;
import com.qinglei.recoup.system.pojo.TimePeriodParam;
import com.qinglei.recoup.system.pojo.MonitorTimeUpdateParam;
import com.qinglei.recoup.system.pojo.MonitorTimeVO;
import com.qinglei.recoup.system.pojo.UpdateMonitorTimeParam;
import com.qinglei.recoup.system.pojo.UpdateOutBedTimeoutParam;
import com.qinglei.recoup.system.service.BedMonitorTimeService;
import com.qinglei.recoup.system.service.BedService;
import com.qinglei.recoup.system.service.BuildingService;
import com.qinglei.recoup.system.service.FloorService;
import com.qinglei.recoup.system.service.MonitorTimeService;
import com.qinglei.recoup.system.service.RoomService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author syp
 */
@Service
@AllArgsConstructor
public class MonitorTimeServiceImpl extends ServiceImpl<MonitorTimeMapper, MonitorTime> implements MonitorTimeService {

    private BedService bedService;

    private BuildingService buildingService;

    private FloorService floorService;

    private RoomService roomService;

    private BedMonitorTimeService bedMonitorTimeService;


    /**
     * 查询检测仪工作配置 (楼层房间床) 树
     *
     * @return
     */
    @Override
    public List<MonitorInfoTreeVO> getMonitorInfoTree() {
        List<MonitorInfoTreeVO> building = getBuilding();
        return building;
    }

    /**
     * 添加检测仪工作时间段
     *
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addMonitorTime(AddMonitorTimeParam param) throws Exception {
        // 处理新增监控时间段
        int type = param.getType();
        int objId;

        if (param.getType() == BedService.TYPE_BED) {
            objId = Integer.parseInt(param.getObjId());
            BedMonitorTimeParam bedMonitorTimeParam = new BedMonitorTimeParam();
            bedMonitorTimeParam.setBedId(objId);
            bedMonitorTimeParam.setStartTime(param.getStartTime());
            bedMonitorTimeParam.setEndTime(param.getEndTime());
            bedMonitorTimeService.addBedMonitorTime(bedMonitorTimeParam);
        } else {
            objId = Integer.parseInt(param.getObjId().substring(1));
            addMonitorTimeInner(param);
        }
        // 所有父级设置监控时间不统一
        this.updateAllParentUnifiedNo(type, objId);
        // 同步当前节点的所有监测时间段给所有子级
        this.syncAllChildrenMonitorTimes(type, objId);
    }

    /**
     * 修改所有父级监控时间不统一
     *
     * @param type
     * @param objId
     */
    private void updateAllParentUnifiedNo(Integer type, Integer objId) {
        if (type == BedService.TYPE_BED) {
            //修改 房间 层 楼 监控时间不统一
            Bed bed = bedService.getBaseMapper().selectById(objId);
            roomService.updateMonitorTimeNo(bed.getRoomId());
            floorService.updateMonitorTimeNo(bed.getFloorId());
            buildingService.updateMonitorTimeNo(bed.getBuildingId());
        } else if (type == BedService.TYPE_ROOM) {
            //修改 层 楼 监控时间不统一
            Room room = roomService.getBaseMapper().selectById(objId);
            floorService.updateMonitorTimeNo(room.getFloorId());
            buildingService.updateMonitorTimeNo(room.getBuildingId());
        } else if (type == BedService.TYPE_FLOOR) {
            //修改   楼 监控时间不统一
            Floor floor = floorService.getBaseMapper().selectById(objId);
            buildingService.updateMonitorTimeNo(floor.getBuildingId());
        }
    }

    /**
     * 将当前节点所有监测时间段同步给素有子级
     *
     * @param type
     * @param objId
     * @throws RedisConnectException
     */
    private void syncAllChildrenMonitorTimes(Integer type, Integer objId) throws RedisConnectException {
        List<MonitorTime> monitorTimes = baseMapper.selectList(Wrappers.<MonitorTime>lambdaQuery()
                .eq(MonitorTime::getType, type)
                .eq(MonitorTime::getObjId, objId));
        if (CollectionUtils.isEmpty(monitorTimes)) {
            return;
        }

        List<TimePeriodParam> monitorTimeList = monitorTimes.stream().map(item -> {
            TimePeriodParam monitorTimeQO = new TimePeriodParam();
            monitorTimeQO.setStartTime(item.getStartTime());
            monitorTimeQO.setEndTime(item.getEndTime());
            return monitorTimeQO;
        }).collect(Collectors.toList());

        if (type == BedService.TYPE_ROOM) {
            //房间需要操作 房间 床  监控时间统一
            roomService.updateMonitorTimeUnified(objId);

            List<Bed> beds = bedService.getBedByRoomId(objId).getData();
            for (Bed bed : beds) {
                bedMonitorTimeService.syncMonitorTimes(monitorTimeList, bed.getId());
            }
        } else if (type == BedService.TYPE_FLOOR) {
            //层需要操作 层 房间 床  监控时间统一
            floorService.updateMonitorTimeUnified(objId);

            List<Room> rooms = roomService.getRoomByFloorId(objId).getData();
            for (Room room : rooms) {
                this.syncMonitorTimes(monitorTimeList, room.getId(), BedService.TYPE_ROOM);
                roomService.updateMonitorTimeUnified(room.getId());
            }
            List<Bed> beds = bedService.getBedByFloorId(objId);
            for (Bed bed : beds) {
                bedMonitorTimeService.syncMonitorTimes(monitorTimeList, bed.getId());
            }
        } else if (type == BedService.TYPE_BUILDING) {
            //楼需要操作 楼 层 房间 床  监控时间统一
            buildingService.updateMonitorTimeUnified(objId);

            List<Floor> floors = floorService.getFloorByBuildingId(objId).getData();
            for (Floor floor : floors) {
                this.syncMonitorTimes(monitorTimeList, floor.getId(), BedService.TYPE_FLOOR);
                floorService.updateMonitorTimeUnified(floor.getId());
            }
            List<Room> rooms = roomService.getRoomByBuildingId(objId);
            for (Room room : rooms) {
                this.syncMonitorTimes(monitorTimeList, room.getId(), BedService.TYPE_ROOM);
                roomService.updateMonitorTimeUnified(room.getId());
            }
            List<Bed> beds = bedService.getBedByBuildingId(objId);
            for (Bed bed : beds) {
                bedMonitorTimeService.syncMonitorTimes(monitorTimeList, bed.getId());
            }
        }
    }

    /**
     * 内部用添加监测时间段
     *
     * @param param
     * @return
     * @throws RecoupException
     */
    private void addMonitorTimeInner(AddMonitorTimeParam param) throws RecoupException {
        int objId = Integer.parseInt(param.getObjId().substring(1));
        boolean checkRes = this.checkTimeOverlap(param.getStartTime(), param.getEndTime(), param.getType(),
                objId, null);
        if (checkRes) {
            throw new RecoupException("时间有冲突，请重新选择时间");
        }

        MonitorTime monitorTime = new MonitorTime();
        monitorTime.setType(param.getType());
        monitorTime.setObjId(objId);
        monitorTime.setStartTime(param.getStartTime());
        monitorTime.setEndTime(param.getEndTime());
        boolean res = this.save(monitorTime);
        if (!res) {
            throw new RecoupException("监测时间段保存失败");
        }
    }

    /**
     * 内部用修改监测时间段
     *
     * @param param
     * @return
     * @throws RecoupException
     */
    private MonitorTime updateMonitorTimeInner(UpdateMonitorTimeParam param) throws RecoupException {
        MonitorTime monitorTime = baseMapper.selectById(param.getMonitorTimeId());
        if (monitorTime == null) {
            throw new RecoupException("监测时间段不存在");
        }
        boolean checkRes = this.checkTimeOverlap(param.getStartTime(), param.getEndTime(), param.getType(),
                monitorTime.getObjId(), monitorTime.getId());
        if (checkRes) {
            throw new RecoupException("时间有冲突，请重新选择时间");
        }
        monitorTime.setStartTime(param.getStartTime());
        monitorTime.setEndTime(param.getEndTime());
        baseMapper.updateById(monitorTime);
        return monitorTime;
    }

    /**
     * 内部用删除监测时间段
     *
     * @param monitorTimeId
     * @return
     * @throws RecoupException
     */
    private MonitorTime delMonitorTimeInner(Integer monitorTimeId) throws RecoupException {
        MonitorTime monitorTime = baseMapper.selectById(monitorTimeId);
        if (monitorTime == null) {
            throw new RecoupException("监测时间段不存在");
        }
        Integer count = getBaseMapper().selectCount(Wrappers.<MonitorTime>lambdaQuery().eq(MonitorTime::getType, monitorTime.getType()).eq(MonitorTime::getObjId, monitorTime.getObjId()));
        if (count < 2){
            throw new RecoupException("监控时间不可全部删除");
        }
        baseMapper.deleteById(monitorTimeId);
        return monitorTime;
    }

    /**
     * 检查时间是否重叠
     *
     * @param startTimeStr
     * @param endTimeStr
     * @param type
     * @param objId
     * @param excludeId
     * @return true - 有重叠 false - 无重叠
     */
    private boolean checkTimeOverlap(String startTimeStr, String endTimeStr, Integer type, Integer objId, Integer excludeId) {
        // 传入时间段
        TimePeriodParam timePeriodIn = new TimePeriodParam(startTimeStr, endTimeStr);

        // 查询监测时间段
        List<MonitorTime> monitorTimes = baseMapper.selectList(Wrappers.<MonitorTime>lambdaQuery()
                .eq(MonitorTime::getType, type)
                .eq(MonitorTime::getObjId, objId)
                .ne(excludeId != null, MonitorTime::getId, excludeId));

        // 遍历比较时间是否有重叠
        for (MonitorTime bmt : monitorTimes) {
            TimePeriodParam timePeriodCur = new TimePeriodParam(bmt.getStartTime(), bmt.getEndTime());
            boolean res = DateTimeUtils.checkTimeOverlap(timePeriodIn, timePeriodCur);
            if (res) {
                return true;
            }
        }
        return false;
    }

    /**
     * 修改检测仪工作时间段
     *
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMonitorTime(UpdateMonitorTimeParam param) throws Exception {
        // 处理新增监控时间段
        int type = param.getType();
        int objId;

        if (param.getType() == BedService.TYPE_BED) {
            MonitorTimeUpdateParam monitorTimeUpdateParam = new MonitorTimeUpdateParam();
            monitorTimeUpdateParam.setId(param.getMonitorTimeId());
            monitorTimeUpdateParam.setStartTime(param.getStartTime());
            monitorTimeUpdateParam.setEndTime(param.getEndTime());
            BedMonitorTime res = bedMonitorTimeService.updateBedMonitorTime(monitorTimeUpdateParam);
            objId = res.getBedId();
        } else {
            MonitorTime res = updateMonitorTimeInner(param);
            objId = res.getObjId();
        }
        // 所有父级设置监控时间不统一
        this.updateAllParentUnifiedNo(type, objId);
        // 同步当前节点的所有监测时间段给所有子级
        this.syncAllChildrenMonitorTimes(type, objId);
    }

    /**
     * 删除检测仪工作时间段
     *
     * @param type
     * @param monitorTimeId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delMonitorTime(Integer type, Integer monitorTimeId) throws Exception {
        int objId;
        // 处理删除监控时间段
        if (type == BedService.TYPE_BED) {
            BedMonitorTime res = bedMonitorTimeService.delBedMonitorTime(monitorTimeId);
            objId = res.getBedId();
        } else {
            MonitorTime res = delMonitorTimeInner(monitorTimeId);
            objId = res.getObjId();
        }
        // 所有父级设置监控时间不统一
        this.updateAllParentUnifiedNo(type, objId);
        // 同步当前节点的所有监测时间段给所有子级
        this.syncAllChildrenMonitorTimes(type, objId);
    }

    /**
     * 根据objid和type查询监控时间
     *
     * @param objId
     * @param type
     * @return
     */
    @Override
    public List<TimePeriodParam> getMonitorTimeByObjIdAndType(Integer objId, Integer type) {
        List<TimePeriodParam> list = new ArrayList<>();
        List<MonitorTime> monitorTimes = baseMapper.selectList(Wrappers.<MonitorTime>lambdaQuery().eq(MonitorTime::getObjId, objId).eq(MonitorTime::getType, type));
        for (MonitorTime sc : monitorTimes) {
            TimePeriodParam monitorTimeQO = new TimePeriodParam();
            monitorTimeQO.setStartTime(sc.getStartTime());
            monitorTimeQO.setEndTime(sc.getEndTime());
            list.add(monitorTimeQO);
        }
        return list;
    }

    /**
     * 修改离床时间阀值
     *
     * @param param
     * @return
     */
    @Override
    public CommonRes updateOutBedTimeout(UpdateOutBedTimeoutParam param) {
        int objId;
        String outBedTimeout = param.getOutBedTimeout();
        Integer type = param.getType();
        //修改床的 离床阀值时间
        if (type == BedService.TYPE_BED) {
            objId = Integer.parseInt(param.getObjId());
            //修改床的 离床阀值时间统一
            boolean flag = bedService.updateOutBedTime(objId, outBedTimeout);
            //修改 楼 层 房间的 离床阀值时间不统一
            Bed bed = bedService.getBaseMapper().selectById(objId);
            buildingService.updateOutBedTimeNo(bed.getBuildingId());
            floorService.updateOutBedTimeNo(bed.getFloorId());
            roomService.updateOutBedTimeNo(bed.getRoomId());
            if (flag) {
                return CommonRes.ok();
            }
        } else if (type == BedService.TYPE_ROOM) {
            objId = Integer.parseInt(param.getObjId().substring(1));
            //修改 房间 床的 离床阀值时间统一
            boolean flag = roomService.updateOutBedTime(objId, outBedTimeout);
            if (flag) {
                List<Bed> data = bedService.getBedByRoomId(objId).getData();
                for (Bed b : data) {
                    bedService.updateOutBedTime(b.getId(), outBedTimeout);
                }
                //修改 楼 层的 离床阀值时间不统一
                Room room = roomService.getBaseMapper().selectById(objId);
                buildingService.updateOutBedTimeNo(room.getBuildingId());
                floorService.updateOutBedTimeNo(room.getFloorId());
                return CommonRes.ok();
            }
        } else if (type == BedService.TYPE_FLOOR) {
            objId = Integer.parseInt(param.getObjId().substring(1));
            //修改 层 房间 床的 离床阀值时间统一
            boolean flag = floorService.updateOutBedTime(objId, outBedTimeout);
            if (flag) {
                List<Room> data = roomService.getRoomByFloorId(objId).getData();
                for (Room room : data) {
                    roomService.updateOutBedTime(room.getId(), outBedTimeout);
                    List<Bed> beds = bedService.getBedByRoomId(room.getId()).getData();
                    for (Bed b : beds) {
                        bedService.updateOutBedTime(b.getId(), outBedTimeout);
                    }
                }
                //修改 楼 层的 离床阀值时间不统一
                Floor floor = floorService.getBaseMapper().selectById(objId);
                buildingService.updateOutBedTimeNo(floor.getBuildingId());
                return CommonRes.ok();
            }

        } else if (type == BedService.TYPE_BUILDING) {
            objId = Integer.parseInt(param.getObjId().substring(1));
            //修改 楼 层 房间 床的 离床阀值时间统一
            boolean flag = buildingService.updateOutBedTime(objId, outBedTimeout);
            if (flag) {
                List<Floor> floors = floorService.getFloorByBuildingId(objId).getData();
                for (Floor floor : floors) {
                    floorService.updateOutBedTime(floor.getId(), outBedTimeout);
                    List<Room> data = roomService.getRoomByFloorId(floor.getId()).getData();
                    for (Room room : data) {
                        roomService.updateOutBedTime(room.getId(), outBedTimeout);
                        List<Bed> beds = bedService.getBedByRoomId(room.getId()).getData();
                        for (Bed b : beds) {
                            bedService.updateOutBedTime(b.getId(), outBedTimeout);
                        }
                    }
                }
                return CommonRes.ok();
            }
        }
        return CommonRes.failed("操作失败");
    }

    /**
     * 同步监控时间
     *
     * @param monitorTimeQOS
     * @param objId
     * @param type
     * @return
     */
    private void syncMonitorTimes(List<TimePeriodParam> monitorTimeQOS, Integer objId, Integer type) {
        // 删除现有监测时间段
        baseMapper.delete(Wrappers.<MonitorTime>lambdaUpdate().eq(MonitorTime::getObjId, objId).eq(MonitorTime::getType, type));
        // 添加新的监测时间段
        for (TimePeriodParam mtq : monitorTimeQOS) {
            MonitorTime monitorTime = new MonitorTime();
            monitorTime.setObjId(objId);
            monitorTime.setType(type);
            monitorTime.setStartTime(mtq.getStartTime());
            monitorTime.setEndTime(mtq.getEndTime());
            getBaseMapper().insert(monitorTime);
        }
    }

    /**
     * 查询楼
     *
     * @return
     */
    private List<MonitorInfoTreeVO> getBuilding() {

        List<MonitorInfoTreeVO> buildingList = new ArrayList<>();
        List<Building> buildings = buildingService.getBaseMapper().selectList(Wrappers.emptyWrapper());
        for (Building b : buildings) {
            MonitorInfoTreeVO monitorInfoTreeVO = new MonitorInfoTreeVO();
            monitorInfoTreeVO.setId(BedService.TREE_BUILDING_PREFIX + b.getId());
            monitorInfoTreeVO.setKey(monitorInfoTreeVO.getId());
            monitorInfoTreeVO.setName(b.getName());
            monitorInfoTreeVO.setType(BedService.TYPE_BUILDING);
            monitorInfoTreeVO.setMonitorTimeUnified(b.getMonitorTimeUnified());
            monitorInfoTreeVO.setOutBedTimeoutUnified(b.getOutBedTimeoutUnified());
            monitorInfoTreeVO.setOutBedTime(b.getOutBedTimeout());
            List<MonitorTime> monitorTimes = baseMapper.selectList(Wrappers.<MonitorTime>lambdaQuery().eq(MonitorTime::getType, BedService.TYPE_BUILDING).eq(MonitorTime::getObjId, b.getId()));
            List<MonitorTimeVO> monitorTime = getMonitorTime(monitorTimes);
            monitorInfoTreeVO.setMonitorTimes(monitorTime);
            monitorInfoTreeVO.setChildren(getFloor(b.getId()));
            buildingList.add(monitorInfoTreeVO);
        }
        return buildingList;
    }

    /**
     * 查询层
     *
     * @return
     */
    private List<MonitorInfoTreeVO> getFloor(Integer id) {

        List<MonitorInfoTreeVO> floorList = new ArrayList<>();
        List<Floor> floors = floorService.getBaseMapper().selectList(Wrappers.<Floor>lambdaQuery().eq(Floor::getBuildingId, id));
        for (Floor f : floors) {
            MonitorInfoTreeVO monitorInfoTreeVO = new MonitorInfoTreeVO();
            monitorInfoTreeVO.setId(BedService.TREE_FLOOR_PREFIX + f.getId());
            monitorInfoTreeVO.setKey(monitorInfoTreeVO.getId());
            monitorInfoTreeVO.setName(f.getName());
            monitorInfoTreeVO.setType(BedService.TYPE_FLOOR);
            monitorInfoTreeVO.setMonitorTimeUnified(f.getMonitorTimeUnified());
            monitorInfoTreeVO.setOutBedTimeoutUnified(f.getOutBedTimeoutUnified());
            monitorInfoTreeVO.setOutBedTime(f.getOutBedTimeout());
            List<MonitorTime> monitorTimes = baseMapper.selectList(Wrappers.<MonitorTime>lambdaQuery().eq(MonitorTime::getType, BedService.TYPE_FLOOR).eq(MonitorTime::getObjId, f.getId()));
            List<MonitorTimeVO> monitorTime = getMonitorTime(monitorTimes);
            monitorInfoTreeVO.setMonitorTimes(monitorTime);
            monitorInfoTreeVO.setChildren(getRoom(f.getId()));
            floorList.add(monitorInfoTreeVO);
        }
        return floorList;
    }

    /**
     * 查询房间
     *
     * @param id
     * @return
     */
    private List<MonitorInfoTreeVO> getRoom(Integer id) {
        List<MonitorInfoTreeVO> roomList = new ArrayList<>();
        List<Room> rooms = roomService.getBaseMapper().selectList(Wrappers.<Room>lambdaQuery().eq(Room::getFloorId, id));
        for (Room r : rooms) {
            MonitorInfoTreeVO monitorInfoTreeVO = new MonitorInfoTreeVO();
            monitorInfoTreeVO.setId(BedService.TREE_ROOM_PREFIX + r.getId());
            monitorInfoTreeVO.setKey(monitorInfoTreeVO.getId());
            monitorInfoTreeVO.setName(r.getName());
            monitorInfoTreeVO.setType(BedService.TYPE_ROOM);
            monitorInfoTreeVO.setMonitorTimeUnified(r.getMonitorTimeUnified());
            monitorInfoTreeVO.setOutBedTimeoutUnified(r.getOutBedTimeoutUnified());
            monitorInfoTreeVO.setOutBedTime(r.getOutBedTimeout());
            List<MonitorTime> monitorTimes = baseMapper.selectList(Wrappers.<MonitorTime>lambdaQuery().eq(MonitorTime::getType, BedService.TYPE_ROOM).eq(MonitorTime::getObjId, r.getId()));
            List<MonitorTimeVO> monitorTime = getMonitorTime(monitorTimes);
            monitorInfoTreeVO.setMonitorTimes(monitorTime);
            monitorInfoTreeVO.setChildren(getBed(r.getId()));
            roomList.add(monitorInfoTreeVO);
        }
        return roomList;
    }

    /**
     * 查询床
     *
     * @param id
     * @return
     */
    private List<MonitorInfoTreeVO> getBed(Integer id) {
        List<MonitorInfoTreeVO> bedList = new ArrayList<>();
        List<Bed> beds = bedService.getBaseMapper().selectList(Wrappers.<Bed>lambdaQuery().eq(Bed::getRoomId, id));
        for (Bed b : beds) {
            MonitorInfoTreeVO monitorInfoTreeVO = new MonitorInfoTreeVO();
            monitorInfoTreeVO.setId(String.valueOf(b.getId()));
            monitorInfoTreeVO.setKey(monitorInfoTreeVO.getId());
            monitorInfoTreeVO.setName(b.getName());
            monitorInfoTreeVO.setType(BedService.TYPE_BED);
            monitorInfoTreeVO.setOutBedTime(b.getOutBedTimeout());
            List<BedMonitorTime> monitorTimes = bedMonitorTimeService.getBaseMapper().selectList(Wrappers.<BedMonitorTime>lambdaQuery().eq(BedMonitorTime::getBedId, b.getId()));
            List<MonitorTimeVO> monitorTime = getBedMonitorTime(monitorTimes);
            monitorInfoTreeVO.setMonitorTimes(monitorTime);
            monitorInfoTreeVO.setMonitorTimeUnified(UNIFIED_YES);
            monitorInfoTreeVO.setOutBedTimeoutUnified(UNIFIED_YES);
            bedList.add(monitorInfoTreeVO);
        }
        return bedList;
    }

    /**
     * 转换楼层房间  监控时间
     *
     * @param monitorTimes
     * @return
     */
    private List<MonitorTimeVO> getBedMonitorTime(List<BedMonitorTime> monitorTimes) {
        List<MonitorTimeVO> monitorTimeVOS = new ArrayList<>();
        for (BedMonitorTime mt : monitorTimes) {
            MonitorTimeVO monitorTimeVO = new MonitorTimeVO();
            monitorTimeVO.setId(mt.getId());
            monitorTimeVO.setStartTime(mt.getStartTime());
            monitorTimeVO.setEndTime(mt.getEndTime());
            monitorTimeVOS.add(monitorTimeVO);
        }
        return monitorTimeVOS;
    }

    /**
     * 转换床  监控时间
     *
     * @param monitorTimes
     * @return
     */
    private List<MonitorTimeVO> getMonitorTime(List<MonitorTime> monitorTimes) {
        List<MonitorTimeVO> monitorTimeVOS = new ArrayList<>();
        for (MonitorTime mt : monitorTimes) {
            MonitorTimeVO monitorTimeVO = new MonitorTimeVO();
            monitorTimeVO.setId(mt.getId());
            monitorTimeVO.setStartTime(mt.getStartTime());
            monitorTimeVO.setEndTime(mt.getEndTime());
            monitorTimeVOS.add(monitorTimeVO);
        }
        return monitorTimeVOS;
    }
}
